package com.app.android.coliy.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.app.android.coliy.R;
import com.app.android.coliy.adapter.FontListAdapter;
import com.app.android.coliy.bean.TypeFaceInfo;
import com.app.android.coliy.interface_.CommCallBack;
import com.app.android.coliy.manager.TypeFaceManager;
import com.app.android.coliy.tool.Log;
import com.app.android.coliy.ui.view.MultiStateView;

import java.util.List;

/**
 * Created by Administrator on 2018/6/20.
 */

public class FontManagerActivity extends BaseActivity {

    public static CommCallBack callBack;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fontmanage);
        initView();
        getData();
    }

    MultiStateView multiplestatusView;
    RecyclerView recyclerview;
    FontListAdapter adapter;

    //初始化控件
    private void initView() {
        setTitle(getString(R.string.title_fout_manage));    //设置标题
        setLeftImgClickListener();  //设置左键返回

        multiplestatusView = findViewById(R.id.multiplestatusView);
        multiplestatusView.setViewState(MultiStateView.ViewState.LOADING);    //页面初始化，默认为加载中状态
        multiplestatusView.setOnRetryListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                multiplestatusView.setViewState(MultiStateView.ViewState.LOADING);
                getData();
            }
        });

        recyclerview = findViewById(R.id.recyclerview);
        recyclerview.setLayoutManager(new LinearLayoutManager(mContext));
        adapter = new FontListAdapter(mContext, new CommCallBack() {
            @Override
            public void onResult(Object obj) {
                Log.i("FontManagerActivity.onResult");
                if (callBack != null) {
                    callBack.onResult(obj);
                    finish();
                }
            }
        });
        recyclerview.setAdapter(adapter);
    }

    //网路请求 获取数据
    private void getData() {
        final List<TypeFaceInfo> list = TypeFaceManager.getTypeFaceInfo();
        adapter.setData(list);
        multiplestatusView.setViewState(MultiStateView.ViewState.CONTENT);
    }

    //点击事件
    @Override
    public void onClick(View view) {
        super.onClick(view);
        Intent intent;
        switch (view.getId()) {
//            case R.id.tv_tohaibao:
//                intent = new Intent(mContext, YaoQing_HaiBaoActivity.class);
//                startActivity(intent);
//                break;

        }
    }
}
